using System;
using System.Web.UI;

public partial class Go : Page
{
    #region Constantns

    private const string DEFAULT_URL = "/Academia/Default.aspx";

    #endregion

    #region Methods

    #region Private

    private bool IsPopup()
    {
        try
        {
            return Request["Popup"] == "1";
        }
        catch (Exception ex)
        {
            return false;
        }
    }

    private bool IsPopupMaximized()
    {
        try
        {
            return Request["PopupMaximized"] == "1";
        }
        catch (Exception ex)
        {
            return false;
        }
    }

    private int PopupWidth()
    {
        try
        {
            return Convert.ToInt16(Request["PopupWidth"]);
        }
        catch (Exception ex)
        {
            return 0;
        }
    }

    private int PopupHeight()
    {
        try
        {
            return Convert.ToInt16(Request["PopupHeight"]);
        }
        catch (Exception ex)
        {
            return 0;
        }
    }

    private string GetLink()
    {
        try
        {
            return Request["Url"];
        }
        catch (Exception ex)
        {
            return DEFAULT_URL;
        }
    }

    private void redirectLink()
    {
        try
        {
            if (IsPopup())
            {
                if (IsPopupMaximized())
                {
                    string scriptPopupMax =
                        @"
        					<script>
        					<!--
        						openWindowMax('" + GetLink() +
                        @"','OpenMaximized');
                                history.go(-1);
        					-->
        					</script>";
                    if (!Page.ClientScript.IsClientScriptBlockRegistered("openPopupMax"))
                        Page.RegisterClientScriptBlock("openPopupMax", scriptPopupMax);
                }
                else
                {
                    string scriptPopup =
                        @"
        					<script>
        					<!--
        						openWindow('" + GetLink() + @"'," +
                        PopupWidth() + @"," + PopupWidth() +
                        @");
                                history.go(-1);
        					-->
        					</script>";
                    if (!Page.ClientScript.IsClientScriptBlockRegistered("openPopup"))
                        Page.RegisterClientScriptBlock("openPopup", scriptPopup);
                }
            }
            else
            {
                Response.Redirect(GetLink());
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    #endregion

    #region Event Handlers

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
            redirectLink();
    }

    #endregion

    #endregion
}